package clues.bihu.cluesaccident

import android.content.Context
import cn.jpush.android.api.JPushInterface
import com.orhanobut.logger.Logger
import java.util.HashSet

class JPushUtil {
    companion object {

        private var count: Int = 0
        /**
         * 设置标签
         */
        fun addTag_ID(mContext: Context) {
            val tags = HashSet<String>()
            tags.add("LX")

            val alias = "LXJQRJPushAccount"+Preference.catchString("flutter."+Preference.AGENTID,"")
            JPushInterface.setAliasAndTags(mContext, alias, tags) { i, s, set ->
                Logger.e("成功"+ alias)
            }
        }


        /**
         * 移除标签
         */
        fun removeTag_ID(mContext: Context) {
            JPushInterface.deleteAlias(mContext, Preference.catchString("flutter."+Preference.AGENTID, "0").toInt())
//            addorupDatejgAccount("")
            //清除推送的所有通知
            JPushInterface.clearAllNotifications(mContext)
            Logger.e("成功"+ Preference.catchString("flutter."+Preference.AGENTID, "0"))
        }

        /**
         * 保存标签到服务器
         */
//        private fun addorupDatejgAccount(account: String) {
//            val map = mapOf(
//                    "AgentId" to "${Preference.catchInt(Preference.AGENTID, 0)}",
//                    "TopAgentId" to "${Preference.catchInt(Preference.TOPAGENTID, 0)}",
//                    "Account" to account)
//            AppHttpClient.getInstance().postDataDefault(UrlConfig.Clue_SaveJgAccount, map, object : ACallback<ResponseResult<String>>() {
//                override fun onSuccess(bean: ResponseResult<String>?) {
//                }
//
//                override fun onFail(errCode: Int, errMsg: String?) {
//                    if(count <3) {
//                        Handler().postDelayed({
//                            addorupDatejgAccount(account)
//                        }, 6000)
//                    }
//                    count++
//                }
//            })
//
//        }

    }
}